/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd. 		   */
/*																   */
/*	NAME	  = t__sqlserver_bigint_add.c						   */
/*	NOTE	  = 												   */
/*	DATE	  = 2014/11/25 by geyh								   */
/*******************************************************************/

#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>

#include <fix/config.h>
#include <fix/fix_core.h>
#include <fix/fix_comm.h>

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_ret = FR_SUCC;
    char arr_inbuff[100] = {0};
    snprintf(arr_inbuff, 100,
             "\x39\x3d\x46\x49\x58\x2e\x34\x2e\x34\x01\x39\x3d\x37\x35\x01\x33\x35\x3d\x41\x01\x33\x34\x3d\x31\x01");
    char *p_inbuff = arr_inbuff;
    unsigned int ui_len = strlen(p_inbuff);
    unsigned int ui_hd_len = 0;
    unsigned int ui_bd_len = 0;
    char *p_version = NULL;
    char *p_msg_type = NULL;

    i_ret = fix_parse_header(p_inbuff, ui_len, &ui_hd_len, &ui_bd_len, &p_version, &p_msg_type);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    return;
}

static void __case2(void)
{
    int i_ret = FR_SUCC;
    char arr_inbuff[100] = {0};
    snprintf(arr_inbuff, 100,
             "\x38\x3d\x46\x49\x58\x2e\x34\x2e\x34\x01\x38\x3d\x37\x35\x01\x33\x35\x3d\x41\x01\x33\x34\x3d\x31\x01");
    char *p_inbuff = arr_inbuff;
    unsigned int ui_len = strlen(p_inbuff);
    unsigned int ui_hd_len = 0;
    unsigned int ui_bd_len = 0;
    char *p_version = NULL;
    char *p_msg_type = NULL;

    i_ret = fix_parse_header(p_inbuff, ui_len, &ui_hd_len, &ui_bd_len, &p_version, &p_msg_type);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    return;
}

static void __case3(void)
{
    int i_ret = FR_SUCC;
    char arr_inbuff[100] = {0};
    snprintf(arr_inbuff, 100,
             "\x38\x3d\x46\x49\x58\x2e\x34\x2e\x34\x01\x39\x3d\x37\x35\x01\x32\x35\x3d\x41\x01\x33\x34\x3d\x31\x01");
    char *p_inbuff = arr_inbuff;
    unsigned int ui_len = strlen(p_inbuff);
    unsigned int ui_hd_len = 0;
    unsigned int ui_bd_len = 0;
    char *p_version = NULL;
    char *p_msg_type = NULL;

    i_ret = fix_parse_header(p_inbuff, ui_len, &ui_hd_len, &ui_bd_len, &p_version, &p_msg_type);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    return;
}

static void __case4(void)
{
    int i_ret = FR_SUCC;
    char arr_inbuff[100] = {0};
    snprintf(arr_inbuff, 100,
             "\x38\x3d\x46\x49\x58\x2e\x34\x2e\x34\x01\x39\x3d\x37\x35\x01\x33\x35\x3d\x41\x01\x33\x34\x3d\x31\x01");
    char *p_inbuff = arr_inbuff;
    unsigned int ui_len = strlen(p_inbuff);
    unsigned int ui_hd_len = 0;
    unsigned int ui_bd_len = 0;
    char *p_version = NULL;
    char *p_msg_type = NULL;

    i_ret = fix_parse_header(p_inbuff, ui_len, &ui_hd_len, &ui_bd_len, &p_version, &p_msg_type);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(ui_hd_len, 20);
    CU_ASSERT_EQUAL(ui_bd_len, 70);
    CU_ASSERT_STRING_EQUAL(p_version, "\x46\x49\x58\x2e\x34\x2e\x34");
    CU_ASSERT_STRING_EQUAL(p_msg_type, "\x41");
    frfree(p_version);
    frfree(p_msg_type);
    return;
}

static void __case5(void)
{
    int i_ret = FR_SUCC;
    char arr_inbuff[100] = {0};
    snprintf(arr_inbuff, 100, "\x38\x3d\x46\x49\x58\x2e\x34\x2e\x34");
    char *p_inbuff = arr_inbuff;
    unsigned int ui_len = strlen(p_inbuff);
    unsigned int ui_hd_len = 0;
    unsigned int ui_bd_len = 0;
    char *p_version = NULL;
    char *p_msg_type = NULL;

    i_ret = fix_parse_header(p_inbuff, ui_len, &ui_hd_len, &ui_bd_len, &p_version, &p_msg_type);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    return;
}

static void __case6(void)
{
    int i_ret = FR_SUCC;
    char arr_inbuff[100] = {0};
    snprintf(arr_inbuff, 100, "\x38\x3d\x46\x49\x58\x2e\x34\x2e\x34\x01\x39\x3d\x37\x35");
    char *p_inbuff = arr_inbuff;
    unsigned int ui_len = strlen(p_inbuff);
    unsigned int ui_hd_len = 0;
    unsigned int ui_bd_len = 0;
    char *p_version = NULL;
    char *p_msg_type = NULL;

    i_ret = fix_parse_header(p_inbuff, ui_len, &ui_hd_len, &ui_bd_len, &p_version, &p_msg_type);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    return;
}

static void __case7(void)
{
    int i_ret = FR_SUCC;
    char arr_inbuff[100] = {0};
    snprintf(arr_inbuff, 100, "\x38\x3d\x46\x49\x58\x2e\x34\x2e\x34\x01\x39\x3d\x37\x35\x01\x33\x35\x3d\x41");
    char *p_inbuff = arr_inbuff;
    unsigned int ui_len = strlen(p_inbuff);
    unsigned int ui_hd_len = 0;
    unsigned int ui_bd_len = 0;
    char *p_version = NULL;
    char *p_msg_type = NULL;

    i_ret = fix_parse_header(p_inbuff, ui_len, &ui_hd_len, &ui_bd_len, &p_version, &p_msg_type);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    return;
}

int add_suite_fix_parse_header(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" fix_parse_header()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    //增加测试用例
    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL ||
        CU_add_test(pSuite, "case5", __case5) == NULL ||
        CU_add_test(pSuite, "case6", __case6) == NULL ||
        CU_add_test(pSuite, "case7", __case7) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}

